#!/usr/bin/env python
# -*- coding: utf-8 -*-

__author__ = 'dong'


import requests
import re
import os
from bs4 import BeautifulSoup

class fsz(object):

    def __init__(self):
        self.s = requests.session()
        self.headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language":"zh-CN,zh;q=0.8",
            "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36",
            "Host": "www.360guakao.com",
            "Referer": "http://www.360guakao.com/fabu.php?cityid=0&catid=36",
            # "Content-Type": "multipart/form-data; charset=UTF-8"
            # "Content-Type": "text/html; charset=gbk"
        }


    def post_msg(self):
        '''

        :return:
        '''

        # url = 'http://www.360guakao.com/member.php'
        #
        # data = {
        #     'mod': 'login',
        #     'action': 'dopost',
        #     'url': '',
        #     'userid': '17727766372',
        #     'userpwd': 'ab654321',
        #     'memory': 'on',
        #     'log_submit': '������¼',
        # }
        #
        # r = self.s.post(url, data)
        # print r.status_code
        # print r.headers
        # print r.text
        t = "<script>window.document.location.href='http://www.360guakao.com/member/index.php';</script>"
        soup = BeautifulSoup(t, 'html.parser')
        print soup.find_all('script')[0].string
        # print soup.find_all('h1')[0].string



        # post_url = 'http://www.360guakao.com/fabu.php?action=input&catid=2&cityid=0'
        # post_url = 'http://www.360guakao.com/fabu.php?action=input&catid={0}&cityid=0'
        #
        #
        # for i in xrange(22, 36):
        #     p = self.s.get(url=post_url.format(str(i)), headers=self.headers)
        #     with open('a/'+str(i)+'.html', 'w') as f:
        #         f.write(p.text.encode('utf-8'))


def test():
    '''

    :return:
    '''

    # self.checkBoxGroup_ft.addButton(self.obj.ui.checkBox_78_1102, 1102)

    for d in os.listdir('a/'):
        # print d
        with open('a/'+d, 'r') as fd:
            s = fd.read()
            resutl = re.findall(r'<option value=\"(.+?)\">', s)

            for i in resutl:
                print 'self.checkBoxGroup_fszcom.addButton(self.obj.ui.checkBox_360com_'+str(i)+', '+str(i)+')'




if __name__ == '__main__':
    f = fsz()
    f.post_msg()
    # test()
